<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
    <title>Document</title>
    <style>
        .red{
            color: red;
        }
    </style>
</head>
<body>
    <div id="app" :class="red">
        {{age}}
        <button @click='age++'>add</button>
        {{ageFun}}



        <p>a:{{a}}</p>
        <p>b:{{b}}</p>
        <button @click='A'>a++</button>
        <button @click='B'>b++</button>


        <button>切换样式</button>
    </div>
    <script>
        new Vue({
            el:'#app',
            data(){
                return{
                    name:'',
                    age:'',
                    a:0,
                    b:0
                }
            },
            watch:{//监听
                age(val,old){
                    //console.log(val,old);
                    if(val>18){
                        alert("危险，数据膨胀");
                        this.age=18;
                    }
                }
            },
            methods:{
                //调用要加括号
                A(){
                    console.log('a执行了');
                    return this.a++;
                },
                B(){
                    console.log('b执行了');
                    return this.b++;
                }
            },
            computed:{
                //计算属性 调用时不要加括号   一定要有return
                ageFun(){
                    return 444444
                }
            }
        })
    </script>
</body>
</html>